package com.ruoyi.system.service.impl;

import java.util.List;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.ShopNoticeMapper;
import com.ruoyi.system.domain.ShopNotice;
import com.ruoyi.system.service.IShopNoticeService;
import com.ruoyi.common.core.text.Convert;

/**
 * 公告Service业务层处理
 *
 * @author ruoyi
 * @date 2020-10-24
 */
@Service
public class ShopNoticeServiceImpl implements IShopNoticeService {
    @Autowired
    private ShopNoticeMapper shopNoticeMapper;

    /**
     * 查询公告
     *
     * @param id 公告ID
     * @return 公告
     */
    @Override
    public ShopNotice selectShopNoticeById(Long id) {
        return shopNoticeMapper.selectShopNoticeById(id);
    }

    /**
     * 查询公告列表
     *
     * @param shopNotice 公告
     * @return 公告
     */
    @Override
    public List<ShopNotice> selectShopNoticeList(ShopNotice shopNotice) {
        return shopNoticeMapper.selectShopNoticeList(shopNotice);
    }

    /**
     * 新增公告
     *
     * @param shopNotice 公告
     * @return 结果
     */
    @Override
    public int insertShopNotice(ShopNotice shopNotice) {
        shopNotice.setCreateTime(DateUtils.getNowDate());
        return shopNoticeMapper.insertShopNotice(shopNotice);
    }

    /**
     * 修改公告
     *
     * @param shopNotice 公告
     * @return 结果
     */
    @Override
    public int updateShopNotice(ShopNotice shopNotice) {
        return shopNoticeMapper.updateShopNotice(shopNotice);
    }

    /**
     * 删除公告对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteShopNoticeByIds(String ids) {
        return shopNoticeMapper.deleteShopNoticeByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除公告信息
     *
     * @param id 公告ID
     * @return 结果
     */
    @Override
    public int deleteShopNoticeById(Long id) {
        return shopNoticeMapper.deleteShopNoticeById(id);
    }

    @Override
    public AjaxResult notice() {

        String notice = shopNoticeMapper.selectShopNoticeById(1L).getContent();

        JSONObject j = new JSONObject();

        j.put("notice", notice);

        return AjaxResult.success(j);
    }
}
